import React from "react";
import RefClassComponent from './RefClassComponent.jsx'
class CreateRef extends React.Component {
  constructor(props) {
    super(props);
    this.el = React.createRef();
    this.child = React.createRef();
  }

  handler = () => {
    this.el.current.innerHTML = Math.random();
  };
  changeName = () => {
    this.child.current.changeName(" father change my name")
  }
  render() {
    return (
      <div>
        ref is a DOM:
        <button onClick={this.handler} ref={this.el}>
          Bton
        </button>
        <hr/>
        ref is a class component:
        <button onClick={this.changeName}>调用子组件实例的changeName方法</button>
        <RefClassComponent ref={this.child}></RefClassComponent>
      </div>
    );
  }
}
export default CreateRef;
